<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->
<!DOCTYPE html>
<html>
<head>
    <title>分销等级</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="/grapheditor/styles/grapheditor.css">
    <script type="text/javascript">
        // Parses URL parameters. Supported parameters are:
        // - lang=xy: Specifies the language of the user interface.
        // - touch=1: Enables a touch-style user interface.
        // - storage=local: Enables HTML5 local storage.
        // - chrome=0: Chromeless mode.
        var urlParams = (function(url)
        {
            var result = new Object();
            var idx = url.lastIndexOf('?');

            if (idx > 0)
            {
                var params = url.substring(idx + 1).split('&');

                for (var i = 0; i < params.length; i++)
                {
                    idx = params[i].indexOf('=');

                    if (idx > 0)
                    {
                        result[params[i].substring(0, idx)] = params[i].substring(idx + 1);
                    }
                }
            }
            console.log(result);
            return result;
        })(window.location.href);

        // Default resources are included in grapheditor resources
        mxLoadResources = false;
    </script>
    <script type="text/javascript" src="/grapheditor/js/Init.js"></script>
    <script type="text/javascript" src="/grapheditor/deflate/pako.min.js"></script>
    <script type="text/javascript" src="/grapheditor/deflate/base64.js"></script>
    <script type="text/javascript" src="/grapheditor/jscolor/jscolor.js"></script>
    <script type="text/javascript" src="/grapheditor/sanitizer/sanitizer.min.js"></script>
    <script type="text/javascript" src="/grapheditor/mxClient.js"></script>
    <script type="text/javascript" src="/grapheditor/js/EditorUi.js"></script>
    <script type="text/javascript" src="/grapheditor/js/Editor.js"></script>
    <script type="text/javascript" src="/grapheditor/js/Sidebar.js"></script>
    <script type="text/javascript" src="/grapheditor/js/Graph.js"></script>
    <script type="text/javascript" src="/grapheditor/js/Format.js"></script>
    <script type="text/javascript" src="/grapheditor/js/Shapes.js"></script>
    <script type="text/javascript" src="/grapheditor/js/Actions.js"></script>
    <script type="text/javascript" src="/grapheditor/js/Menus.js"></script>
    <script type="text/javascript" src="/grapheditor/js/Toolbar.js"></script>
    <script type="text/javascript" src="/grapheditor/js/Dialogs.js"></script>
    <script type="text/javascript" src="/common/js/jquery-2.1.4.min.js"></script>
</head>
<body class="geEditor">
<script type="text/javascript">
    var editorUiInitGl ;
    var pageType='0';
    // Extends EditorUi to update I/O action states based on availability of backend
    (function()
    {

        var editorUiInit = EditorUi.prototype.init;

        EditorUi.prototype.init = function()
        {
            editorUiInit.apply(this, arguments);
            var _thisEditor = this;
            $.ajax({
                type: 'GET',
                url: "/default",
                data: {},
                success: function (result) {
                   if(result!=""){
                       showDefaultXML(_thisEditor,result);
                   }
                }
            });

        };

        // Adds required resources (disables loading of fallback properties, this can only
        // be used if we know that all keys are defined in the language specific file)
        // mxResources.loadDefaultBundle = false;
        var bundle = mxResources.getDefaultBundle(RESOURCE_BASE, mxLanguage) ||
            mxResources.getSpecialBundle(RESOURCE_BASE, mxLanguage);

        // Fixes possible asynchronous requests
        // alert(STYLE_PATH);
        mxUtils.getAll([bundle, STYLE_PATH + '/default.xml'], function(xhr)
        {

            // Adds bundle text to resources
            // 国际化
            mxResources.parse(xhr[0].getText());

            // Configures the default graph theme
            var themes = new Object();
            themes[Graph.prototype.defaultThemeName] = xhr[1].getDocumentElement();

            // Main
            // 初始化界面
            new EditorUi(new Editor(urlParams['chrome'] == '0', themes));



        }, function()
        {
            // document.body.innerHTML = '<center style="margin-top:10%;">Error loading resource files. Please check browser console.</center>';
        });
    })();

    function showMessage() {
        console.log(mxUtils.getPrettyXml(editorUiInitGl.editor.getGraphXml()));
    }

    function  showDefaultXML(_obj,result) {
        var error = null;
        // _obj.editor.graph.model.beginUpdate();
        try
        {
            var data = result;
            var doc = mxUtils.parseXml(data);
            var model = new mxGraphModel();
            var codec = new mxCodec(doc);
            codec.decode(doc.documentElement, model);

            var children = model.getChildren(model.getChildAt(model.getRoot(), 0));
            _obj.editor.graph.importCells(children)


            // LATER: Why is hideDialog between begin-/endUpdate faster?
            // _obj.hideDialog();
        }
        catch (e)
        {
            error = e;
        }
        finally
        {
            // _obj.editor.graph.model.endUpdate();
        }
    }
</script>
</body>
</html>
